<?php
header("Content-type: text/javascript; charset=utf8");

include_once "config.php";

define( "D_FOLDER", "themes/" );
define( "D_SITE", "http://ok.onlife.mobi/".D_FOLDER );

$ret = array("error"=>0);

$db->real_query("SELECT * FROM `themes` WHERE `author`!='team' ORDER BY `id` ASC LIMIT 0, 50 ");

$q = $db->store_result();

if ( $q && $q->num_rows > 0 ){
	
	$ret['themes'] = array();
	
	while ( $arr = $q->fetch_array( MYSQLI_ASSOC ) )
	{
		if ( !file_exists( D_FOLDER . $arr['folder'] . "/" . $arr['folder'] . ".css" ) )
			continue;
		
		$ret['themes'][] = array( "id"=>intval($arr['id']),
									//"title"=>iconv("CP1251","UTF-8",$arr['title']),
									"title"=>$arr['title'],
									"file"=>D_SITE . $arr['folder'] . "/" . $arr['folder'] . ".css",
									"preview"=>D_SITE . $arr['folder'] . "/" . $arr['preview'],
									"author"=>$arr['author']);
	}
	
} else $ret['error'] = 1;


echo json_encode($ret);
